package com.aaa.controller.mht;

import cn.hutool.core.util.ObjectUtil;
import com.aaa.aspect.LogMonitor;
import com.aaa.controller.BaseController;
import com.aaa.entity.fpa.QuestionFpa;
import com.aaa.entity.mht.QuestionMht;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.Result;
import com.aaa.service.mht.QuestionMhtService;
import com.github.pagehelper.Page;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping("/questionMht")
public class QuestionMhtController extends BaseController {

    @Resource
    private QuestionMhtService questionMhtService;

    //查询所有
    @RequestMapping(method = RequestMethod.GET, value = "/queryAll.do")
    @ResponseBody
    public Result queryAll(PageSortEntity pageSortEntity, QuestionMht questionMht) {
        Page pageResult = questionMhtService.queryAll(pageSortEntity, questionMht);
        return success(pageResult.getResult(), pageResult.getTotal());
    }

    //添加
    @LogMonitor
    @RequestMapping("/insert.do")
    @ResponseBody
    public Result insert(QuestionMht questionMht) {
        boolean user1 = questionMhtService.insert(questionMht);
        if (user1) {
            return success();
        } else {
            return fail();
        }
    }

    //批量删除和单条删除
    @LogMonitor
    @RequestMapping("/delete.do")
    @ResponseBody
    public Result delete(String[] ids) {
        List list = new ArrayList();
        for (String id : ids) {
            list.add(id);
        }
        boolean user1 = questionMhtService.delete(list);
        if (user1) {
            return success();
        } else {
            return fail();
        }
    }

    //修改
    @LogMonitor
    @RequestMapping("/update.do")
    @ResponseBody
    public Result update(QuestionMht questionMht) {
        boolean user1 = questionMhtService.update(questionMht);
        if (user1) {
            return success();
        } else {
            return fail();
        }
    }

    //id唯一性校验
    @GetMapping("repetitionId.do")
    public Result repetitionId(QuestionMht questionMht) {
        boolean b = false;
        if (ObjectUtil.isNotEmpty(questionMht.getId())) {
            b = this.questionMhtService.repetitionId(questionMht);
        } else {
            return fail("不能为空哦！");
        }
        if (b) {
            return success("问题可用");
        }
        return fail("问题重复，不可用");
    }

    //问题唯一性校验
    @GetMapping("repetitionName.do")
    public Result repetitionName(QuestionMht questionMht) {
        if (ObjectUtil.isNotEmpty(questionMht.getQuestion())) {
            boolean b = this.questionMhtService.repetitionName(questionMht);
            if (b) {
                return success("问题可用");
            } else {
                return fail("问题重复，不可用");
            }
        }
        return fail("不能为空哦！");
    }

}

